<?php 
	include('template/header.php');
	include('classess/login.php');

	$tr_admin = new admin_login();	
	if(isset($_POST['user_email'])){
		$trn_login = $tr_admin->user_login();		
	}
	
?>
	<section  class="homepage-slider" id="home-slider">
		<div class="flexslider">
			<ul class="slides">
				<li>
					<img src="img/slider/first_image.jpg" alt="No Image" />					
				</li>
				<li>
					<img src="img/slider/second_image.jpg" alt="No Image" />					
				</li>
			</ul>
		</div>			
	</section>					
	<section class="main-content">				
		<div class="row">
			<div class="span12" style="text-align:center;">					
				<h4 class="title"><span class="text"><strong>Login</strong> Form</span></h4>
				<?php 
					if(isset($trn_login)){										
				?>
				<div class="alert alert-error">
					<div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
					<div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $trn_login; ?></div>
					<div style="clear:both;"></div>							
				</div>
				<?php
					}
				?>
				<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="email_subscribe" >
					<input type="hidden" name="next" value="/">
					<fieldset>
						<div class="control-group">
							<label class="control-label">Email</label>
							<div class="controls">
								<input type="text" name="user_email" id="user_email"  placeholder="Email" class="input-xlarge">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">Password</label>
							<div class="controls">
								<input type="password" name="user_pwd" id="user_pwd"  placeholder="Password" class="input-xlarge">
							</div>
						</div>
						<div class="control-group">
							<button tabindex="3" type="submit" class="btn btn-inverse large subscribe_button">Login</button> 
						</div>
					</fieldset>
				</form>	 			
			</div>				
		</div>
	</section>
   
<?php include('template/footer.php'); ?>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		$('.subscribe_button').click(function(){
						
			if($('#user_email').val() == ""){
				alert("Please enter a value for the \"Email\" field.");
				$('#user_email').focus();				
				return (false);
			}
			else if(($('#user_email').val().indexOf("\@") == -1) || ($('#user_email').val().indexOf(".")== -1) || isInvalidateEmail($('#user_email').val())){
				alert("Invalid Email Address");
				$('#user_email').focus();
				return (false);
			}
			else if($('#user_pwd').val() == ''){			
				alert("Please enter a value for the \"Password\" field.");
				$('#user_pwd').focus();
				return (false);
			}else{
				document.email_subscribe.submit();
			}

		});

		$('.close').click(function(){
			$('.alert-error').addClass('hide');
		});
		
	});

	function isInvalidateEmail(str)
	{
		var atpos=str.indexOf("@");
		var dotpos=str.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=str.length)
		  {
		  return true;
		  }
		return false;
	}

</script>